@echo off
chcp 65001 >nul
echo ============================================================
echo Conda环境安装脚本
echo ============================================================
echo.

REM 配置
set ENV_NAME=hand_gesture
set PYTHON_VERSION=3.9

echo 环境名称: %ENV_NAME%
echo Python版本: %PYTHON_VERSION%
echo.

REM 步骤1: 删除旧环境（如果存在）
echo [步骤1] 检查并删除旧环境...
conda env list | findstr /C:"%ENV_NAME%" >nul
if %errorlevel% == 0 (
    echo 环境 '%ENV_NAME%' 已存在，正在删除...
    call conda env remove -n %ENV_NAME% -y
    echo ✓ 已删除旧环境
) else (
    echo 环境不存在，跳过删除
)
echo.

REM 步骤2: 创建新环境
echo [步骤2] 创建新环境 '%ENV_NAME%' (Python %PYTHON_VERSION%)...
call conda create -n %ENV_NAME% python=%PYTHON_VERSION% -y
if errorlevel 1 (
    echo 错误: 创建环境失败
    pause
    exit /b 1
)
echo ✓ 环境创建成功
echo.

REM 步骤3: 激活环境
echo [步骤3] 激活环境 '%ENV_NAME%'...
call conda activate %ENV_NAME%
if errorlevel 1 (
    echo 错误: 激活环境失败
    pause
    exit /b 1
)
echo ✓ 环境已激活
echo.

REM 步骤4: 安装依赖
echo [步骤4] 安装项目依赖...
if not exist requirements.txt (
    echo 错误: 未找到 requirements.txt 文件
    pause
    exit /b 1
)

echo 升级 pip...
python -m pip install --upgrade pip

echo 安装依赖包（这可能需要几分钟）...
pip install -r requirements.txt
if errorlevel 1 (
    echo 错误: 安装依赖失败
    pause
    exit /b 1
)
echo ✓ 依赖安装成功
echo.

REM 步骤5: 验证安装
echo [步骤5] 验证安装...
python -c "import tensorflow; print('TensorFlow:', tensorflow.__version__)" 2>nul
python -c "import cv2; print('OpenCV:', cv2.__version__)" 2>nul
python -c "import ultralytics; print('Ultralytics: 已安装')" 2>nul
echo.

echo ============================================================
echo ✓ 环境安装完成！
echo ============================================================
echo.
echo 当前已激活环境: %ENV_NAME%
echo.
echo 接下来可以运行:
echo   1. 数据预处理:  python preprocess_data.py
echo   2. 模型训练:    python train_gesture_model.py
echo   3. 运行程序:    python main.py
echo.
echo 如需退出环境，运行: conda deactivate
echo ============================================================
echo.
pause

